package com.nq.activaity.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nq.activaity.entity.StUserInviteRecord;
import com.nq.activaity.service.IStUserInviteRecordService;
import com.nq.common.Result;
import com.nq.common.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 邀请赠送积分表
 * @Author: jeecg-boot
 * @Date:   2024-11-07
 * @Version: V1.0
 */
@RestController
@RequestMapping("/user/userInviteRecord")
@Slf4j
public class StUserInviteRecordController {

	@Autowired
	private IStUserInviteRecordService stUserInviteRecordService;

	 /**
	  * 邀请记录
	  * @param req
	  * @return
	  */
	 @RequestMapping({"list.do"})
	 @ResponseBody
	 public ServerResponse list(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								HttpServletRequest req) {
		 ServerResponse response = stUserInviteRecordService.list(pageNo, pageSize, req);
		 return response;
	 }
	
	/**
	 *   添加
	 *
	 * @param stUserInviteRecord
	 * @return
	 */
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody StUserInviteRecord stUserInviteRecord) {
		stUserInviteRecordService.save(stUserInviteRecord);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param stUserInviteRecord
	 * @return
	 */
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody StUserInviteRecord stUserInviteRecord) {
		stUserInviteRecordService.updateById(stUserInviteRecord);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		stUserInviteRecordService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.stUserInviteRecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		StUserInviteRecord stUserInviteRecord = stUserInviteRecordService.getById(id);
		if(stUserInviteRecord==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(stUserInviteRecord);
	}

//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param stUserInviteRecord
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, StUserInviteRecord stUserInviteRecord) {
//        return super.exportXls(request, stUserInviteRecord, StUserInviteRecord.class, "邀请赠送积分表");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, StUserInviteRecord.class);
//    }

}
